package com.wxp.demo08.list;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.wxp.demo08.R;
import com.wxp.demo08.list.adapter.PlanetGridAdapter;
import com.wxp.demo08.list.model.PlanetModel;
import com.wxp.demo08.util.ToastUtil;

import java.util.List;

/**
 * 2.3 网格视图GridView
 */
public class GridViewActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {

    private GridView gv_planet;
    private List<PlanetModel> planetList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_grid_view);
        this.setTitle("2.3 网格视图GridView");

        gv_planet = findViewById(R.id.gv_planet);
        planetList = PlanetModel.getDefaultList();
        //创建适配器
        PlanetGridAdapter adapter = new PlanetGridAdapter(this, planetList);
        gv_planet.setAdapter(adapter);
        gv_planet.setOnItemClickListener(this);
        //设置拉升模式
        gv_planet.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        ToastUtil.show(this, "您选择了：" + planetList.get(position).name);
    }
}